<template>
    <div>
        <Layout>
            <el-form ref="form" :model="form" label-width="120px" class="form" slot="main">
                <el-form-item label="知识库的类别">
                    <el-radio-group v-model="form.type">
                    <el-radio label="文档知识库"></el-radio>
                    <el-radio label="表格知识库"></el-radio>
                    <el-radio label="资源知识库"></el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="知识库的名称">
                    <el-input type="text" v-model="form.name"></el-input>
                </el-form-item> 
                <el-form-item label="知识库的详情">
                    <el-input type="text" v-model="form.desc"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submit">立即创建</el-button>
                    <el-button>取消</el-button>
                </el-form-item>
            </el-form>
        </Layout>
    </div>
</template>
<script>
import Layout from '../../components/Layout.vue'
export default {
    components: {
        Layout
    },
    data() {
        return {
            form: {
                name: '',
                type: '',
                desc: ''
            }
        }
    },
    methods: {
        submit() {
            console.log(this.form.type)
            if (!this.form.type) {
                return alert('请选择知识库的类别')
            }
            this.$axios.post('/api/knowledge/add', {
                type: this.form.type,
                name: this.form.name,
                detail: this.form.desc
            }).then(res => {
                if(res.data.code === 1) {
                    // 添加成功
                    this.$router.push(`/knowledge/list?id=${res.data.id}`)
                } else {
                    alert('添加失败')
                }
            })
        }
    },

}
</script>
<style lang="scss">
    .form {
        width: 500px;
    }
    
</style>